package com.whfc.ms.api.emp.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.EmpDataDTO;
import com.whfc.emp.param.EmpAttendPlan;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.emp.service.MsAppEmpAttendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 人员报表数据
 *
 * @author guodong_sun
 * @Description:
 * @date 2019年8月1日
 */
@RestController
@RequestMapping("/ms/api")
public class AppEmpReportController extends BaseController {

    @Autowired
    private MsAppEmpAttendService msAppEmpAttendService;

    /**
     * 项目人员每日统计
     *
     * @param user
     * @param pageNum
     * @param pageSize
     * @param deptId
     * @return
     */
    @GetMapping(value = {"/data/emp/list", "/emp/dept/data/list"})
    public Result empDeptDataList(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                  @RequestParam("pageNum") Integer pageNum,
                                  @RequestParam("pageSize") Integer pageSize,
                                  @RequestParam(value = "deptId") Integer deptId,
                                  @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("startDate") Date startDate,
                                  @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("endDate") Date endDate) {
        logger.info("人员总运行数据,loginer:{},pageNum:{},pageSize:{},deptId:{},startDate:{},endDate:{}", user.getUsername(), pageNum, pageSize, deptId, startDate, endDate);
        PageData<EmpDataDTO> pageData = msAppEmpAttendService.empDayList(deptId, startDate, endDate, pageNum, pageSize);
        return ResultUtil.success(pageData);
    }

    /**
     * 项目人员计划出勤设置
     *
     * @return
     */
    @PostMapping("/emp/dept/data/plan")
    public Result empDeptDataPlan(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                  @RequestBody @Validated EmpAttendPlan plan) {
        logger.info("项目人员计划出勤设置,user:{}", user.getUsername(), plan);
        msAppEmpAttendService.setEmpDataPlan(plan);
        return ResultUtil.success();
    }

}
